/*******************************************************************************
** 文件名称：avr_it.c
** 文件作用：中断函数源文件
** 编写作者：Tom Free 付瑞彪
** 编写时间：2018-10-19
** 文件备注：
**
**
** 更新记录：
**          2018-10-19 -> 将以前文件进行整理                         <Tom Free>
**
**          1 Tab == 4 Spaces     UTF-8     ANSI C Language (C99)
*******************************************************************************/

#include "typedef.h"
#include "chip.h"
#include "uart0.h"
#include "serialport.h"
#include "soft_timer.h"
#include "timer0.h"

#define STRINGVECTOR(x) #x

#define VECTOR_ID(x) STRINGVECTOR(vector = (x))

#define INTERRUPT_HANDLER(isr_fun_name, isr_vect)   \
    _Pragma(VECTOR_ID((isr_vect)))                  \
    __interrupt void isr_fun_name(void)

#if 0
#define RESET_vect               (0x00) /* External Pin, Power-on Reset, Brown-out Reset and Watchdog Reset */
#define INT0_vect                (0x02) /* External Interrupt Request 0 */
#define INT1_vect                (0x04) /* External Interrupt Request 1 */
#define TIMER2_COMP_vect         (0x06) /* Timer/Counter2 Compare Match */
#define TIMER2_OVF_vect          (0x08) /* Timer/Counter2 Overflow */
#define TIMER1_CAPT_vect         (0x0A) /* Timer/Counter1 Capture Event */
#define TIMER1_COMPA_vect        (0x0C) /* Timer/Counter1 Compare Match A */
#define TIMER1_COMPB_vect        (0x0E) /* Timer/Counter1 Compare Match B */
#define TIMER1_OVF_vect          (0x10) /* Timer/Counter1 Overflow */
#define TIMER0_OVF_vect          (0x12) /* Timer/Counter0 Overflow */
#define SPI_STC_vect             (0x14) /* Serial Transfer Complete */
#define USART_RXC_vect           (0x16) /* USART, Rx Complete */
#define USART_UDRE_vect          (0x18) /* USART Data Register Empty */
#define USART_TXC_vect           (0x1A) /* USART, Tx Complete */
#define ADC_vect                 (0x1C) /* ADC Conversion Complete */
#define EE_RDY_vect              (0x1E) /* EEPROM Ready */
#define ANA_COMP_vect            (0x20) /* Analog Comparator */
#define TWI_vect                 (0x22) /* 2-wire Serial Interface */
#define SPM_RDY_vect             (0x24) /* Store Program Memory Ready */
#endif

///* 串口0接收完成中断处理函数 */
//INTERRUPT_HANDLER(USART0_RXC_Handler, USART_RXC_vect)
//{
//    /* 接收一个字符处理 */
//    //SerialPort_ReceiveByteHandler(0);
//}
//
///* 串口0发送完成中断处理函数 */
//INTERRUPT_HANDLER(USART0_TXC_Handler, USART_TXC_vect)
//{
//    /* 发送一个字符处理 */
//    //SerialPort_SendByteHandler(0);
//}

/* TC0溢出中断处理函数 */
INTERRUPT_HANDLER(TIMER0_OVF_Handler, TIMER0_OVF_vect)
{
    /* 设置初值 */
    TIMER0_SetTCNT0(255 - 125);

    /* 发送一个字符处理 */
    SoftTimer_TicksHandle();
}
